<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'

import { JeecgListMixin } from '@/mixins/JeecgListMixin'

import { getAction } from '@api/manage'

export default {
  name: 'HfPurchaseinputDetailModelList',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      description: '采购入库管理页面',
      currentDeptId: '',
      orderId: '',
      checkshow: true,
      submitflag: true,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '物料代码',
          align: 'center',
          dataIndex: 'materialCode'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '单箱数',
          align: 'center',
          dataIndex: 'perNumber'
        },
        {
          title: '箱数',
          align: 'center',
          dataIndex: 'number'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'totalNumber'
        },
        {
          title: '收料仓库',
          align: 'center',
          dataIndex: 'warehouseName_dictText'
        },
        {
          title: '物料库存',
          align: 'center',
          dataIndex: 'warehouseMaterial'
        }
      ],
      url: {
        list: '/purchase/hfPurchaseInput/listHfPurchaseinputDetailModelByMainId'
      },
      dictOptions: {
        supplier: [],
        purchaseType: [],
        sourceType: [],
        isRed: []
      },
      superFieldList: []
    }
  },
  created() {},
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {},

    searchReset() {
      this.queryParam = {}
      this.loadData(1)
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      let params = this.getQueryParams() //查询条件
      params.purchaseinputId = this.currentDeptId
      getAction(this.url.list, params).then(res => {
        if (res.success && res.result) {
          debugger
          if (res.message == '1') {
            this.submitflag = false
          }
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
        }
      })
    },

    select(record) {
      this.currentDeptId = record.id
      this.orderId = record.parentId
      if (this.currentDeptId == '' || this.currentDeptId == null) {
        this.$message.error('请选择一个采购入库单!')
      } else {
        this.loadData(1)
      }
    },
    clearList() {
      this.currentDeptId = ''
      this.dataSource = []
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
